<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 2, 3, 4, 5];
            let result = arr.reduce((tol, cur) => (tol += cur), 0);
            console.log(result);
            // 实现二维数组求和
            let arr1 = [1, 2, 3, [3, 4, 5], 7, 8];
            let result1 = arr1
                .toString()
                .split(',')
                .reduce((tol, cur) => (tol += Number(cur)), 0);
            console.log(result1);
        </script>
    </body>
</html>
